﻿using Hyt.Passport.Service;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Hyt.Passport;

namespace Hyt.Test
{
    
    
    /// <summary>
    ///这是 DepartmentServiceTest 的测试类，旨在
    ///包含所有 DepartmentServiceTest 单元测试
    ///</summary>
    [TestClass()]
    public class DepartmentServiceTest
    {

        /// <summary>
        ///Remove 的测试
        ///</summary>
        [TestMethod()]
        public void DepartmentService_RemoveTest()
        {
            using (TestUnitOfWork unit = new TestUnitOfWork())
            {
                DepartmentService service = unit.Get<DepartmentService>();
                Department dpt = new Department
                {
                    Name = "_testname",
                    Code = "99"
                };
                service.Create(dpt);
                unit.Commit();
            }

            Guid id=new Guid();
            using (TestUnitOfWork unit = new TestUnitOfWork())
            {
                DepartmentService service = unit.Get<DepartmentService>();
                var dpt = service.Get("99");
                Assert.IsNotNull(dpt);
                if (dpt != null)
                {
                    id = dpt.Id;
                }
                unit.Commit();
            }

            using (TestUnitOfWork unit = new TestUnitOfWork())
            {
                DepartmentService service = unit.Get<DepartmentService>();
                service.Remove(id);
                unit.Commit();
            }

            using (TestUnitOfWork unit = new TestUnitOfWork())
            {
                DepartmentService service = unit.Get<DepartmentService>();
                var dpt = service.Get("99");
                Assert.IsNull(dpt);
                unit.Commit();
            }
        }
    }
}
